package com.se7en.ufutil;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

public class GatorLocationOverlay extends MyLocationOverlay {
	Bitmap Gator;
	float CircleRad;
	public GatorLocationOverlay(Context context, MapView mapView) {
		super(context, mapView);
		Log.d("Paul", "Gator Location Overlay Constructed");
		Gator = BitmapFactory.decodeResource(context.getResources(), R.drawable.uf_logo);
	}
	
	@Override
	protected void drawMyLocation(Canvas canvas, MapView mapView,
			Location lastFix, GeoPoint myLocation, long when) {
		//super.drawMyLocation(canvas, mapView, lastFix, myLocation, when);
		Point nextDrawingPoint = new Point();
		mapView.getProjection().toPixels(myLocation, nextDrawingPoint);
		
		CircleRad = lastFix.getAccuracy();
		Paint circle = new Paint();
	    circle.setColor(Color.BLUE);
	    circle.setAlpha(80);
	    int myCircleRadius = metersToRadius(CircleRad, mapView, (double)myLocation.getLatitudeE6()/1000000);
	    canvas.drawCircle(nextDrawingPoint.x, nextDrawingPoint.y, myCircleRadius, circle);
		
		canvas.drawBitmap(Gator, nextDrawingPoint.x - Gator.getWidth()/2, nextDrawingPoint.y - Gator.getHeight()/2, null);
		
		
			
		
		
	}
	
	public static int metersToRadius(float meters, MapView map, double latitude) {
	    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
	}

}
